package com.kirayous.task;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.batch.BatchDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@SpringBootApplication
public class Task1Application {





    private static ApplicationContext ac;
    public static void main(String[] args) {


        //这个方法会返回一个ApplicationContext对象
        ac=SpringApplication.run(Task1Application.class, args);
    }




//    @Bean
//    public CommandLineRunner commandLineRunner(ApplicationContext ac)
//    {
//        return args ->
//        {
//            System.out.println("打印所有beans");
//            String [] names=ac.getBeanDefinitionNames();
//            Arrays.sort(names);
//            Arrays.stream(names).forEach(System.out::println);
//        };
//    }



    //原来是进入了SpringApplication.run(Task1Application.class, args);之后，
    // 才会扫描bean并且识别出commandLineRunner ；调用里面的run方法结束之后，
    // 才会返回ApplicationContext对象
//    @Component
//    class CommandLineRunnerImpl implements CommandLineRunner
//    {
//
//        @Override
//        public void run(String... args) throws Exception {
//
//            System.out.println("打印所有beans");
//            String [] names=ac.getBeanDefinitionNames();
//            Arrays.sort(names);
//            Arrays.stream(names).forEach(System.out::println);
//        }
//    }

}
